#!/bin/bash

module="wifihack"
device="wifihack"
mode="664"
# invoke insmod with all arguments we got
# and use a pathname, as newer modutils don't look in . by default
echo "Trying unloading module..."
/sbin/rmmod ./$module &> /dev/null
echo "Loading module..."
/sbin/insmod ./$module.ko staticAlloc=0 cdevDim=20 ODoW=1 $* || exit 1

echo "Trying removing chardev..."
rm -f /dev/${device}

# Next command checks for /proc/devices to find the device the 
# driver wants to register to and sets it up
echo "Stripping major number from registered device..."
major=$(awk "\$2==\"/dev/$module\" {print \$1}" /proc/devices)


echo "Creating new chardev..."
mknod /dev/${device}  c $major 0
# give appropriate group/permissions, and change the group.
# Not all distributions have staff, some have "wheel" instead.
group="staff"
grep -q '^staff:' /etc/group || group="wheel"
chgrp $group /dev/${device}
chmod $mode /dev/${device}
